package com.cskaoyan.wordmemorize.controller.admin;


import com.cskaoyan.wordmemorize.aop_whh.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocBookDTO;
import com.cskaoyan.wordmemorize.request.*;
import com.cskaoyan.wordmemorize.service.VocBookService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/voc")
public class VocBookController {

    @Resource
    VocBookService vocBookService;
    //获取书籍列表
    @RequestMapping("book/list")
    public Result<PageDTO<VocBookDTO>> list(VocBookPageRequest pageRequest){
        PageDTO<VocBookDTO> page = vocBookService.getBookPage(pageRequest);
        return Result.ok(page);
    }
    //添加书籍
    @PostMapping("/book")
    @OperateLog(dateType = "书籍",operateType = 1)
    public Result<String> add(@RequestBody VocBookCommand book){
        vocBookService.addVocBook(book);
        return Result.ok();
    }
    //修改书籍
    @PutMapping("/book")
    @OperateLog(dateType = "书籍",operateType = 4)
    public Result<String> update(@RequestBody VocBookCommand book){
        vocBookService.updateVocBook(book);
        return Result.ok();
    }
    //删除书籍
    @DeleteMapping("/book/{bookId}")
    @OperateLog(dateType = "书籍",operateType = 2)
    public Result<String> delete(@PathVariable("bookId") Long bookId){
        vocBookService.deleteVocBook(bookId);
        return Result.ok();
    }
    //批量删除书籍
    @OperateLog(dateType = "书籍",operateType = 3)
    @DeleteMapping("books")
    public Result<String> deleteBatch(@RequestBody BatchDeleteCommand command){
        vocBookService.deleteVocBooks(command);
        return Result.ok();
    }
    //根据类目Id查找书籍
    @RequestMapping("book/list/{categoryId}")
    public Result<PageDTO<VocBookDTO>> listByCategoryId(@PathVariable("categoryId") Long categoryId, VocBookPageRequest pageRequest){
        pageRequest.setKeyword(String.valueOf(categoryId));
        PageDTO<VocBookDTO> page = vocBookService.getBookPage(pageRequest);
        return Result.ok(page);
    }
}
